package com.beta.cms.common.until;

public class ResultMapUtils {

	public static final String SUCCESS_CODE = "200";
	public static final String SUCCESS_MSG = "success";

	/**
	 * 方法执行成功调用的返回值方法
	 * 
	 * @param result
	 * @return
	 */
	public static DataModel<Object> getResultMap(Object result) {
		DataModel<Object> dm = new DataModel<Object>();
		dm.setCode(SUCCESS_CODE);
		dm.setMessage(SUCCESS_MSG);
		dm.setData(result);
		return dm;
	}

	/**
	 * 方法有误时调用的返回值方法
	 * 
	 * @param errorCode
	 *            错误码
	 * @param errorMsg
	 *            错误信息
	 * @return
	 */
	public static DataModel<Object> getFailResultMap(String errorCode, String errorMsg) {
		DataModel<Object> dm = new DataModel<Object>();
		dm.setCode(errorCode);
		dm.setMessage(errorMsg);
		return dm;
	}

	/**
	 * 
	 * @Description 重载
	 * @param result
	 * @param code
	 * @param msg
	 * @return
	 */
	public static DataModel<Object> getResultMap(Object result, String code, String msg) {
		DataModel<Object> dm = new DataModel<Object>();
		dm.setData(result);
		dm.setCode(code);
		dm.setMessage(msg);
		return dm;
	}

	public static DataModel<Object> failGetting() {
		DataModel<Object> dm = new DataModel<Object>();
		dm.setCode(ContantStr.GET_ERROR_KEY);
		dm.setMessage(ContantStr.GET_ERROR_VALUE);
		return dm;
	}

	public static DataModel<Object> failInserting() {
		DataModel<Object> dm = new DataModel<Object>();
		dm.setCode(ContantStr.INSERT_ERROR_KEY);
		dm.setMessage(ContantStr.INSERT_ERROR_VALUE);
		return dm;
	}

	public static DataModel<Object> failUpdating() {
		DataModel<Object> dm = new DataModel<Object>();
		dm.setCode(ContantStr.UPDATE_ERROR_KEY);
		dm.setMessage(ContantStr.UPDATE_ERROR_VALUE);
		return dm;
	}

	public static DataModel<Object> failDeleting() {
		DataModel<Object> dm = new DataModel<Object>();
		dm.setCode(ContantStr.DELETE_ERROR_KEY);
		dm.setMessage(ContantStr.DELETE_ERROR_VALUE);
		return dm;
	}
}
